package com.google.code.mergeinformer.model;

import javax.persistence.*;
import java.util.Date;

/**
 * @author Dmitry Golubev
 */
@NamedQueries({
        @NamedQuery(name = "Revision.allAuthors", query = "SELECT DISTINCT r.author FROM Revision r ORDER BY r.author")
})
@Entity
@Table(name = "revision")
public class Revision extends DefaultEntity implements Comparable<Revision> {

    @Column(name = "number", nullable = false)
    private long number;

    @Column(name = "rev_timestamp", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date timestamp;

    @Column(name = "author", nullable = false)
    private String author;

    @Column(name = "rev_comment")
    private String comment;

    @ManyToOne
    @JoinColumn(name = "id_task")
    private Task task;

    protected Revision() {
    }

    public Revision(long number, Date timestamp, String author, String comment) {
        this.number = number;
        this.timestamp = timestamp;
        this.author = author;
        this.comment = comment;
    }

    public long getNumber() {
        return number;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public String getAuthor() {
        return author;
    }

    public String getComment() {
        return comment;
    }

    public Task getTask() {
        return task;
    }

    void setNumber(long number) {
        this.number = number;
    }

    void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    void setAuthor(String author) {
        this.author = author;
    }

    void setComment(String comment) {
        this.comment = comment;
    }

    void setTask(Task task) {
        this.task = task;
    }

    @Override
    public int compareTo(Revision that) {
        return timestamp.compareTo(that.timestamp);
    }
}
